﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ITS.Infrastructure.Helpers
{
    public static class StringHelper
    {
        public static string[] ParseString(string tags, char separator = ',')
        {
            var result = new List<string>();
            if (!String.IsNullOrWhiteSpace(tags))
            {
                string[] values = tags.Split(new char[] { separator }, StringSplitOptions.RemoveEmptyEntries);
                foreach (string val1 in values)
                    if (!String.IsNullOrEmpty(val1.Trim()))
                        result.Add(val1.Trim());
            }
            return result.ToArray();
        }

        public static string FirstCharacters(string normalString)
        {
            string[] words = StringHelper.ParseString(normalString, ' ');
            StringBuilder sb = new StringBuilder();
            foreach (string w in words)
            {
                sb.Append(w[0]);
            }

            return sb.ToString();
        }

        private static readonly string[] VietnameseSigns = new string[] { "aAeEoOuUiIdDyY", "áàạảãâấầậẩẫăắằặẳẵ", "ÁÀẠẢÃÂẤẦẬẨẪĂẮẰẶẲẴ", "éèẹẻẽêếềệểễ", "ÉÈẸẺẼÊẾỀỆỂỄ", "óòọỏõôốồộổỗơớờợởỡ", "ÓÒỌỎÕÔỐỒỘỔỖƠỚỜỢỞỠ", "úùụủũưứừựửữ", "ÚÙỤỦŨƯỨỪỰỬỮ", "íìịỉĩ", "ÍÌỊỈĨ", "đ", "Đ", "ýỳỵỷỹ", "ÝỲỴỶỸ" };

        public static string RemoveSign4VietnameseString(string str)
        {
            //Tiến hành thay thế , lọc bỏ dấu cho chuỗi
            for (int i = 1; i < VietnameseSigns.Length; i++)
            {
                for (int j = 0; j < VietnameseSigns[i].Length; j++)
                    str = str.Replace(VietnameseSigns[i][j], VietnameseSigns[0][i - 1]);
            }
            return str;
        }
    }
}
